import { defineStore } from 'pinia'

/**
 * 作者: 石兴龙
 * 抖音: 程序员小石
 * 微信: Codingxiaoshi
 */
export const systemStore = defineStore('system', {
  state: () => ({
    // 播放器状态
    audioStatus: 'stop', // stop | play
    audioIndex: 0,
    audioList: [
      {
        label: '泉水',
        audioImg: '/mp3/cover/泉水.webp',
        audioSrc: '/mp3/泉水.m4a',
        audioLyc: '/mp3/泉水.lyc'
      },
      {
        label: '光阴的故事',
        audioImg: '/mp3/cover/光阴的故事.jpg',
        audioSrc: '/mp3/光阴的故事.m4a',
        audioLyc: '/mp3/光阴的故事.lyc'
      },
      {
        label: '难说再见',
        audioImg: '/mp3/cover/难说再见.webp',
        audioSrc: '/mp3/难说再见.m4a',
        audioLyc: '/mp3/难说再见.lyc'
      },
    ]
  }),
  getters: {
    currentAudio(state) {
      const current = state.audioList[state.audioIndex]
      return current
    }
  },
  actions: {
    setAudioStatus(status: 'stop' | 'play') {
      this.audioStatus = status
    },
    audioPrev() {
      this.audioIndex--
      if (this.audioIndex < 0) {
        this.audioIndex = this.audioList.length - 1
      }
    },
    audioNext() {
      this.audioIndex++
      if (this.audioIndex > this.audioList.length - 1) {
        this.audioIndex = 0
      }
    }
  }
})
